class Solution {
public:
    vector<int> exchange(vector<int>& nums) {
        int odd_pos = nums.size() - 1, even_pos = 0;
        while(odd_pos > even_pos){
            while(odd_pos > even_pos && !(nums[odd_pos] & 1))odd_pos--;
            while(odd_pos > even_pos && nums[even_pos] & 1)even_pos++;
            if(odd_pos > even_pos)swap(nums[odd_pos], nums[even_pos]);
            else break;
        }
        return nums;
    }
};
//2021.4.13 
